﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WISD.CarFriend.Web.Admin.Utility
{
    public class BasicPage : System.Web.UI.Page
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public BasicPage()
        {
            this.Load += new EventHandler(BasicPage_Load);
        }


        /// <summary>
        /// 加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BasicPage_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] == null || Session["UserCode"] == null || Session["UserName"] == null || Session["UserType"] == null || Session["UserPermission"] == null || Session["UserRole"] == null)
            {
                Response.Write("<script>parent.location.href='/Admin/Login.aspx'</script>");
                Response.End();
            }
        }


        /// <summary>
        /// 验证用户权限
        /// </summary>
        /// <param name="permission"></param>
        protected void CheckPermission(string permission)
        {
            //string messageBox = "";
            //messageBox += "<script type=\"text/javascript\">\n";
            //messageBox += "parent.jsmsg(350,230,\"警告提示\",\"<b>没有管理权限</b>您没有权限管理该功能，请勿非法进入。\",\"back\")\n";
            //messageBox += "</script>\n";
            //Response.Write(messageBox);
            //Response.End();
        }


        /// <summary>
        /// 遮罩提示窗口
        /// </summary>
        /// <param name="width">宽度</param>
        /// <param name="height">高度</param>
        /// <param name="title">窗口标题</param>
        /// <param name="message">提示文字</param>
        /// <param name="url">返回地址</param>
        /// <param name="css">CSS样式</param>
        protected void ShowMessageBox(int width, int height, string title, string message, string url, string css)
        {
            string script = "";
            script += "<script type=\"text/javascript\">\n";
            script += "parent.jsmsg(" + width + "," + height + ",\"" + title + "\",\"" + message + "\",\"" + url + "\",\"" + css + "\")\n";
            script += "</script>\n";
            ClientScript.RegisterClientScriptBlock(Page.GetType(), "JsMsg", script);
        }


        /// <summary>
        /// 可以自动关闭的提示窗口
        /// </summary>
        /// <param name="title">提示文字</param>
        /// <param name="url">返回地址</param>
        /// <param name="css">CSS样式</param>
        protected void ShowMessageBox(string title, string url, string css)
        {
            string script = "";
            script += "<script type=\"text/javascript\">\n";
            script += "parent.jsprint(\"" + title + "\",\"" + url + "\",\"" + css + "\")\n";
            script += "</script>\n";
            ClientScript.RegisterClientScriptBlock(Page.GetType(), "JsPrint", script);
        }


        /// <summary>
        /// 添加前缀http://
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public string AddHttp(string url)
        {
            url = url.ToLower().Trim();
            if (url.Substring(0, 7) == "http://")
            {
                return url;
            }
            else
            {
                return "http://" + url;
            }
        }


        /// <summary>
        /// 过滤特殊字符
        /// 防止Sql注入
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public string FilterSpecial(string str)
        {
            if (str == "")
            {
                return str;
            }
            else
            {
                str = str.Replace("'", "");
                str = str.Replace("<", "");
                str = str.Replace(">", "");
                str = str.Replace("%", "");
                str = str.Replace("'delete", "");
                str = str.Replace("''", "");
                str = str.Replace("\"\"", "");
                str = str.Replace(",", "");
                str = str.Replace(".", "");
                str = str.Replace(">=", "");
                str = str.Replace("=<", "");
                str = str.Replace("-", "");
                str = str.Replace("_", "");
                str = str.Replace(";", "");
                str = str.Replace("||", "");
                str = str.Replace("[", "");
                str = str.Replace("]", "");
                str = str.Replace("&", "");
                str = str.Replace("/", "");
                str = str.Replace("-", "");
                str = str.Replace("|", "");
                str = str.Replace("?", "");
                str = str.Replace(">?", "");
                str = str.Replace("?<", "");
                str = str.Replace(" ", "");
                return str;
            }
        }



        /// <summary>
        /// 设置视频播放器
        /// </summary>
        /// <param name="url">视频文件路径</param>
        /// <param name="width">播放器显示宽度</param>
        /// <param name="height">播放器显示高度</param>
        /// <returns>播放器内容</returns>
        protected string SetVideo(string url, int width, int height)
        {
            string html = "";    // 播放器内容 
            string videoType = string.Empty;    // 播放器类型

            videoType = url.Substring(url.LastIndexOf('.') + 1).ToLower().Trim();
            if (videoType != null && videoType.Trim() != "")
            {
                switch (videoType)
                {
                    case "wmv":
                        html += " <object id=\"player\" height=\"" + height + "\" width=\"" + width + "\" classid=\"CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6\"> ";
                        html += " <param NAME=\"AutoStart\" VALUE=\"-1\"> ";
                        html += " <!--是否自动播放--> ";
                        html += " <param NAME=\"Balance\" VALUE=\"0\"> ";
                        html += " <!--调整左右声道平衡,同上面旧播放器代码--> ";
                        html += " <param name=\"enabled\" value=\"-1\"> ";
                        html += " <!--播放器是否可人为控制--> ";
                        html += " <param NAME=\"EnableContextMenu\" VALUE=\"-1\"> ";
                        html += " <!--是否启用上下文菜单--> ";
                        html += " <param NAME=\"url\" value=\"" + url + "\"> ";
                        html += " <!--播放的文件地址从数据库中获取视频文件地址--> ";
                        html += " <param NAME=\"PlayCount\" VALUE=\"1\"> ";
                        html += " <!--播放次数控制,为整数--> ";
                        html += " <param name=\"rate\" value=\"1\"> ";
                        html += " <!--播放速率控制,1为正常,允许小数,1.0-2.0--> ";
                        html += " <param name=\"currentPosition\" value=\"0\"> ";
                        html += " <!--控件设置:当前位置--> ";
                        html += " <param name=\"currentMarker\" value=\"0\"> ";
                        html += " <!--控件设置:当前标记--> ";
                        html += " <param name=\"defaultFrame\" value=\"\"> ";
                        html += " <!--显示默认框架--> ";
                        html += " <param name=\"invokeURLs\" value=\"0\"> ";
                        html += " <!--脚本命令设置:是否调用URL--> ";
                        html += " <param name=\"baseURL\" value=\"\"> ";
                        html += " <!--脚本命令设置:被调用的URL--> ";
                        html += " <param name=\"stretchToFit\" value=\"0\"> ";
                        html += " <!--是否按比例伸展--> ";
                        html += " <param name=\"volume\" value=\"50\"> ";
                        html += " <!--默认声音大小0%-100%,50则为50%--> ";
                        html += " <param name=\"mute\" value=\"0\"> ";
                        html += " <!--是否静音--> ";
                        html += " <param name=\"uiMode\" value=\"mini\"> ";
                        html += " <!--播放器显示模式:Full显示全部;mini最简化;None不显示播放控制,只显示视频窗口;invisible全部不显示--> ";
                        html += " <param name=\"windowlessVideo\" value=\"0\"> ";
                        html += " <!--如果是0可以允许全屏,否则只能在窗口中查看--> ";
                        html += " <param name=\"fullScreen\" value=\"0\"> ";
                        html += " <!--开始播放是否自动全屏--> ";
                        html += " <param name=\"enableErrorDialogs\" value=\"-1\"> ";
                        html += " <!--是否启用错误提示报告--> ";
                        html += " <param name=\"SAMIStyle\" value> ";
                        html += " <!--SAMI样式--> ";
                        html += " <param name=\"SAMILang\" value> ";
                        html += " <!--SAMI语言--> ";
                        html += " <param name=\"SAMIFilename\" value> ";
                        html += " <!--字幕ID--> ";
                        html += " </object> ";
                        break;
                    default:
                        break;
                }
            }
            else
            {
                html = "";
            }

            return html;
        }

    }
}